﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.realtime {
    import Engine.Managers.*;
    import Classes.*;
    import Modules.stats.experiments.*;
    import flash.external.*;

    public class RealtimeManager {

        public static var m_realtimeObserver:RealtimeObserver = null;

        public static function get inExperiment():Boolean{
            var _local1:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_REALTIME);
            if (_local1 == ExperimentDefinitions.REALTIME_ENABLED){
                return (true);
            };
            return (false);
        }
        public static function get inSendExperiment():Boolean{
            var _local1:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_SEND_REALTIME);
            if (_local1 == ExperimentDefinitions.SEND_REALTIME_ENABLED){
                return (true);
            };
            return (false);
        }
        public static function onRTStatusChange(_arg1:String, _arg2:String):void{
            if (!inExperiment){
                return;
            };
            var _local3:Friend = RealtimeMethods.getFriendByZid(_arg1);
            var _local4:String;
            if (_local3){
                StatsManager.count("zoom", "show", "presence", _arg2);
                switch (_arg2){
                    case "online":
                        _local3.m_online = true;
                        _local4 = (_local3.m_name + " came online");
                        break;
                    case "offline":
                        _local3.m_online = false;
                        _local4 = (_local3.m_name + " went offline");
                        break;
                };
                if (Global.ui.m_friendBar.scrollingList){
                    Global.ui.m_friendBar.scrollingList.updateFriend(_local3);
                    Global.ui.showTickerMessage(_local4);
                };
            };
        }
        public static function callMethodOnOnlineUser(_arg1:String, _arg2:RealtimeMethod):void{
            var zid:* = _arg1;
            var method:* = _arg2;
            if (!inSendExperiment){
                return;
            };
            try {
                ExternalInterface.call("sendChat", zid, method.jsonString);
            } catch(error:Error) {
            };
        }
        public static function onRTChat(_arg1:String, _arg2:String):void{
            if (!LoadingManager.worldLoaded){
                return;
            };
            var _local3:RealtimeMethod = new RealtimeMethod();
            _local3.createFromString(_arg2);
            _local3.zid = _arg1;
            _local3.execute();
        }
        public static function callMethodOnAllOnlineUsers(_arg1:RealtimeMethod):void{
            var method:* = _arg1;
            if (!inSendExperiment){
                return;
            };
            try {
                ExternalInterface.call("broadcastChat", method.jsonString);
            } catch(error:Error) {
            };
        }

    }
}//package Modules.realtime 
